package com.mmall.seckill.controller;

import com.mmall.seckill.common.Const;
import com.mmall.seckill.common.Result;
import com.mmall.seckill.service.SeckillUserService;
import com.mmall.seckill.vo.LoginVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * Created by megan on 2018/6/16.
 * 登录controller
 */
@Slf4j
@Controller
@RequestMapping("/login/")
public class LoginController {

    @Resource
    private SeckillUserService seckillUserService;

    @RequestMapping("login.page")
    public String toLogin(){
        return Const.page.LOGIN_PAGE;
    }

    /**
     * 用户登录
     * @return
     */
    @RequestMapping(value = "login.do",method = RequestMethod.POST)
    @ResponseBody
    public Result doLogin(@Valid LoginVo loginVo,HttpServletResponse response){
        return seckillUserService.login(response,loginVo);
    }
}
